export default {
  /**
   * @description: 消息提示
   * @param {*} title 标题
   * @param {*} func 完成回调
   * @return {*}
   */
  msg(title, func) {
    uni.showToast({
      title,
      icon: 'none',
      complete: () => {
        setTimeout(() => {
          func && func()
        }, 1500)
      }
    })
  },
  // 成功消息
  msgSuccess(title) {
    uni.showToast({
      title,
      icon: 'success'
    })
  },
  // 错误消息
  msgError(title) {
    uni.showToast({
      title,
      icon: 'error'
    })
  },
  // 隐藏消息
  hideMsg() {
    uni.hideToast()
  },
  // 弹出提示
  modal({ title = '', content = '' }) {
    return new Promise(resolve => {
      uni.showModal({
        title,
        content: content,
        showCancel: false,
        success: res => {
          if (res.confirm) {
            resolve()
          }
        }
      })
    })
  },
  // 确认窗体
  confirm({ title = '', content = '' }) {
    return new Promise(resolve => {
      uni.showModal({
        title,
        content,
        cancelText: '取消',
        confirmText: '确定',
        success: res => {
          if (res.confirm) {
            resolve(true)
          } else {
            resolve(false)
          }
        }
      })
    })
  },
  // 打开遮罩层
  loading(title = '加载中', mask = true) {
    uni.showLoading({
      title,
      mask: mask
    })
  },
  // 关闭遮罩层
  closeLoading() {
    uni.hideLoading()
  }
}
